package com.gxa.service.upgoodsservice.upGoodsServiceImpl;

import com.gxa.dao.upgoods.UpGoodsMapper;
import com.gxa.service.upgoodsservice.UpGoodsService;
import com.gxa.util.SqlSessionFactoryUtils;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;

import java.util.HashMap;
import java.util.Map;

public class UpGoodsServiceImpl implements UpGoodsService {


    @Override
    public String findName(String barcode) {
        SqlSessionFactory sqlSessionFactory = SqlSessionFactoryUtils.getSqlSessionFactory();
        SqlSession sql = sqlSessionFactory.openSession(true);
        UpGoodsMapper mapper = sql.getMapper(UpGoodsMapper.class);
        String nameByCode = mapper.findNameByCode(barcode);
        return nameByCode;
    }

    @Override
    public String findDanWei(String barcode) {
        SqlSessionFactory sqlSessionFactory = SqlSessionFactoryUtils.getSqlSessionFactory();
        SqlSession sql = sqlSessionFactory.openSession(true);
        UpGoodsMapper mapper = sql.getMapper(UpGoodsMapper.class);
        String danWei = mapper.findDanWei(barcode);
        return  danWei;
 }

    @Override
    public Boolean addGoods( String barcode, Integer count) {
        SqlSessionFactory sqlSessionFactory = SqlSessionFactoryUtils.getSqlSessionFactory();
        SqlSession sql = sqlSessionFactory.openSession(true);
        UpGoodsMapper mapper = sql.getMapper(UpGoodsMapper.class);
        Map<String ,Object> map = new HashMap<>();
        map.put("count",count);
        map.put("barcode",barcode);
        Boolean aBoolean = mapper.updateCount(map);
        return aBoolean;
    }


}
